package main

import (
	"fmt"
	"strconv"
)

type Good interface {
	settleAccount() int
	orderInfo() string
}

type Phone struct {
	name    string
	quality int
	price   int
}

func (phone Phone) settleAccount() int {
	return phone.quality * phone.price
}

func (phone Phone) orderInfo() string {
	return "您要购买" + strconv.Itoa(phone.quality) + "个" +
		phone.name + "计：" + strconv.Itoa(phone.settleAccount()) + "元"
}

type FreeGift struct {
	name    string
	quality int
	price   int
}

func (freeGift FreeGift) settleAccount() int {
	return freeGift.quality * freeGift.price
}

func (freeGift FreeGift) orderInfo() string {
	return "您要购买" + strconv.Itoa(freeGift.quality) + "个" +
		freeGift.name + "共计：" + strconv.Itoa(freeGift.settleAccount()) + "元"
}

func calPrice(goods []Good) int {
	var totalPrice int
	for _, good := range goods {
		fmt.Println(good.orderInfo())
		totalPrice = totalPrice + good.settleAccount()
	}
	return totalPrice
}

func main() {
	apple := Phone{
		name:    "apple",
		quality: 10,
		price:   20,
	}

	gift := FreeGift{
		name:    "气球",
		quality: 10,
		price:   0,
	}
	goods := []Good{apple, gift}
	price := calPrice(goods)
	fmt.Printf("本次购物共消费: %d 元", price)
}
